package com.example.demo.common;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-08-28
 * Time:14:06
 */

import lombok.Data;

import java.io.Serializable;

/**
 * 统一数据格式返回
 */
@Data
public class AjaxResult implements Serializable {

    // 状态码
    private Integer code;

    // 状态码的描述信息
    private String msg;

    // 返回的数据
    private Object data;

    /**
     * 操作成功返回的结果
     */
    public static  AjaxResult success(Object date){
        AjaxResult result = new AjaxResult();

        result.setCode(200);
        result.setMsg("");
        result.setData(date);

        return result;
    }

    public static  AjaxResult success(int code,Object date){
        AjaxResult result = new AjaxResult();

        result.setCode(code);
        result.setMsg("");
        result.setData(date);

        return result;
    }

    public static  AjaxResult success(int code,String msg,Object date){
        AjaxResult result = new AjaxResult();

        result.setCode(code);
        result.setMsg(msg);
        result.setData(date);

        return result;
    }

    /**
     * 返回失败结果
     */
    public static AjaxResult fail(int code,String msg){
        AjaxResult result = new AjaxResult();

        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);

        return result;
    }

    public static AjaxResult fail(int code,String msg,Object date){
        AjaxResult result = new AjaxResult();

        result.setCode(code);
        result.setMsg(msg);
        result.setData(date);

        return result;
    }
}
